home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / omega / o.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-06  |  8.9 KB  |  276 lines

  1. /* omega copyright (c) 1987,1988 by Laurence Raphael Brothers */
  2.  
  3. /* this file includes main() and some top-level functions */
  4. /* o.c */
  5.  
  6. #include <signal.h>
  7.  
  8. #include "odefs.h"
  9.  
  10. #include "oextern.h"
  11.  
  12. #include "ominit.h"
  13.  
  14. #include "oiinit.h"
  15.  
  16. /* most globals originate in o.c */
  17.  
  18. /* one of each spell */
  19. struct spell Spells[NUMSPELLS+1];
  20.  
  21. /* locations of city sites [0] - found, [1] - x, [2] - y */
  22. int CitySiteList[NUMCITYSITES][3];
  23.  
  24. /* Currently defined in caps since it is now a variable, was a constant */
  25. int LENGTH=MAXLENGTH; 
  26. int WIDTH=MAXWIDTH;
  27.  
  28. int GameStatus=0L;                    /* Game Status bit vector */
  29. int ScreenLength;                     /* How large is level window */
  30. struct player Player;                 /* the player */
  31. struct terrain Country[MAXWIDTH][MAXLENGTH];/* The countryside */
  32. struct level *City=NULL;              /* The city of Rampart */
  33. struct level *TempLevel=NULL;         /* Place holder */
  34. struct level *Level=NULL;             /* Pointer to current Level */
  35. struct level *Dungeon=NULL;           /* Pointer to current Dungeon */
  36. int Villagenum;                       /* Current Village number */ 
  37. int ScreenOffset;                     /* Offset of displayed screen to level */
  38. int MaxDungeonLevels;                 /* Deepest level allowed in dungeon */
  39. int Current_Dungeon= -1;              /* What is Dungeon now */
  40. int Current_Environment= E_CITY;      /* Which environment are we in */
  41. int Last_Environment= E_COUNTRYSIDE;  /* Which environment were we in */
  42. int Dirs[2][9];                       /* 9 xy directions */
  43. char Cmd='s';                         /* last player command */
  44. int Command_Duration = 0;             /* how long does current command take */
  45. struct monster *Arena_Monster=NULL;   /* Opponent in arena */
  46. int Arena_Opponent=0;                 /* case label of opponent in l_arena()*/
  47. int Arena_Victory;                    /* did player win in arena? */
  48. int Imprisonment=0;                   /* amount of time spent in jail */
  49. int Precipitation=0;                  /* Hours of rain, snow, etc */
  50. int Lunarity=0;                       /* Effect of the moon on character */
  51. int Phase;                            /* Phase of the moon */
  52. int Date;                             /* Starting date */
  53. int Pawndate;                         /* Pawn Shop item generation date */
  54. pob Pawnitems[PAWNITEMS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
  55. /* items in pawn shop */
  56. int SymbolUseHour= -1;                /* holy symbol use marker */
  57. int ViewHour= -1;                     /* crystal ball use marker */
  58. int ZapHour= -1;                      /* staff of enchantment use marker */
  59. int HelmHour= -1;                     /* helm of teleportation use marker*/
  60. int Constriction=0;                   /* Dragonlord Attack State */
  61. int Blessing=FALSE;                   /* Altar Blessing State */
  62. int LastDay= -1;                      /* DPW date of dole */
  63. int RitualHour= -1;                   /* last use of ritual magic */
  64. int RitualRoom= -1;                   /* last room of ritual magic */
  65. int Lawstone=0;                       /* magic stone counter */
  66. int Chaostone=0;                      /* magic stone counter */
  67. int Mindstone=0;                      /* magic stone counter */
  68. int Searchnum = 1;                    /* number of times to search on 's' */
  69. int Verbosity = VERBOSE;              /* verbosity level */
  70. char Seed;                            /* random seed */
  71. int Time = 0;                         /* turn number */
  72. int Tick = 0;                         /* 10 a turn; action coordinator */
  73. char Stringbuffer[10][80] = {
  74.   "First String",  "First String",  "First String",  "First String",  
  75.   "First String",  "First String",  "First String",  "First String",
  76.   "First String",  "First String"}; /* last 10 strings */
  77. int Gymcredit = 0;                    /* credit at rampart gym */
  78. int Spellsleft = 0;                   /* research allowance at college */
  79. int StarGemUse = 0;                   /* last date of star gem use */
  80. int HiMagicUse = 0;                   /* last date of high magic use */
  81. int HiMagic = 0;                      /* current level for l_throne */ 
  82. int Balance = 0;                      /* bank account */
  83. int FixedPoints = 0;                  /* points are frozen after adepthood*/
  84. int LastTownLocX=0;            /* previous position in village or city */
  85. int LastTownLocY=0;            /* previous position in village or city */
  86. int LastCountryLocX=0;            /* previous position in countryside */
  87. int LastCountryLocY=0;            /* previous position in countryside */
  88. char Password[64];                    /* autoteller password */
  89. char Str1[100],Str2[100],Str3[100],Str4[100];
  90.    /* Some string space, random uses */
  91.  
  92. pol Condoitems=NULL;                        /* Items in condo */
  93.  
  94. /* high score names, levels, behavior */
  95. int Shadowlordbehavior,Archmagebehavior,Primebehavior,Commandantbehavior;
  96. int Championbehavior,Priestbehavior[7],Hibehavior,Dukebehavior;
  97. int Chaoslordbehavior,Lawlordbehavior,Justiciarbehavior;
  98. char Shadowlord[80],Archmage[80],Prime[80],Commandant[80],Duke[80];
  99. char Champion[80],Priest[7][80],Hiscorer[80],Hidescrip[80];
  100. char Chaoslord[80],Lawlord[80],Justiciar[80];
  101. int Shadowlordlevel,Archmagelevel,Primelevel,Commandantlevel,Dukelevel;
  102. int Championlevel,Priestlevel[7],Hiscore,Hilevel,Justiciarlevel;
  103. int Chaoslordlevel,Lawlordlevel,Chaos,Law;
  104.  
  105. /* This may be implementation dependent */
  106. /* SRANDFUNCTION is defined in odefs.h */
  107. void initrand()
  108. {
  109.   SRANDFUNCTION;
  110. }
  111.  
  112.  
  113. int game_restore(argc,argv)
  114. int argc;
  115. char *argv[];
  116. {
  117.   char savestr[80];
  118.   int ok;
  119.   if (argc==2) {
  120.     strcpy(savestr,argv[1]);
  121.     ok = restore_game(savestr);
  122.     unlink(savestr);
  123.     if (! ok) {
  124.       endgraf();
  125.       printf("Try again with the right save file, luser!\n");
  126.       exit(0);
  127.     }
  128.     return(TRUE);
  129.   }
  130.   else return(FALSE);
  131. }
  132.  
  133.  
  134. main(argc,argv)
  135. int argc;
  136. char *argv[];
  137. {
  138.   int continuing;
  139.  
  140.  
  141.   /* always catch ^c and hang-up signals */
  142.  
  143.   signal(SIGINT,quit);
  144.   signal(SIGHUP,signalsave);
  145.  
  146.   if (CATCH_SIGNALS) {
  147.     signal(SIGQUIT,signalexit);
  148.     signal(SIGILL,signalexit);
  149.     signal(SIGTRAP,signalexit);
  150.     signal(SIGIOT,signalexit);
  151.     signal(SIGEMT,signalexit);
  152.     signal(SIGFPE,signalexit);
  153.     signal(SIGBUS,signalexit);
  154.     signal(SIGSEGV,signalexit);
  155.     signal(SIGSYS,signalexit);
  156.     }
  157.  
  158.  
  159.  
  160.   /* if filecheck is 0, some necessary data files are missing */
  161.   if (filecheck() == 0) exit(0);
  162.  
  163.   /* all kinds of initialization */
  164.   initgraf();
  165.   initdirs();
  166.   initrand();
  167.   inititem();
  168.   initspells();
  169.  
  170.   strcpy(Stringbuffer[0],"First String");
  171.   strcpy(Stringbuffer[1],"First String");
  172.   strcpy(Stringbuffer[2],"First String");
  173.   strcpy(Stringbuffer[3],"First String");
  174.   strcpy(Stringbuffer[4],"First String");
  175.   strcpy(Stringbuffer[5],"First String");
  176.   strcpy(Stringbuffer[6],"First String");
  177.   strcpy(Stringbuffer[7],"First String");
  178.   strcpy(Stringbuffer[8],"First String");
  179.   strcpy(Stringbuffer[9],"First String");
  180.  
  181.  
  182.   /* game restore attempts to restore game if there is an argument */
  183.   continuing = game_restore(argc,argv);
  184.  
  185.  
  186.   /* monsters initialized in game_restore if game is being restored */  
  187.   if (! continuing) {
  188.     initplayer();
  189.     
  190.     Date = random_range(360);
  191.     Phase = random_range(24);
  192.     moon_check();
  193.     strcpy(Password,"");
  194.  
  195.     init_world();
  196.     
  197.     mprint("'?' for help or commandlist, 'Q' to quit.");
  198.   }
  199.   else mprint("Your adventure continues....");
  200.  
  201.   dataprint();
  202.   timeprint();
  203.   showflags();
  204.  
  205.   screencheck(Player.y);
  206.  
  207.  /* game cycle */
  208.   time_clock(TRUE);
  209.   while (TRUE) {
  210.     if (Current_Environment == E_COUNTRYSIDE)
  211.       p_country_process();
  212.     else time_clock(FALSE);
  213.   }
  214. }
  215.  
  216. int signalexit()
  217. {
  218.   mprint("Yikes!");
  219.   morewait();
  220.   mprint("Sorry, caught a core-dump signal.");
  221.   mprint("Want to try and save the game?");
  222.   if (ynq()=='y')
  223.     save(FALSE); /* don't compress */
  224.   mprint("Bye!");
  225.   endgraf();
  226.   exit(0);
  227. }
  228.  
  229.  
  230.  
  231.  
  232. /* Start up game with new dungeons; start with player in city */
  233. void init_world()
  234. {
  235.   if (Level != NULL) free((char *) Level);
  236.   if (City != NULL) free((char *) City);
  237.   if (TempLevel != NULL) free((char *) TempLevel);
  238.   if (Dungeon != NULL) free_dungeon();
  239.   City = Level = TempLevel = Dungeon = NULL;
  240.   load_country();
  241.   load_city();
  242.   change_environment(E_CITY);
  243.   locprint("The City of Rampart.");
  244. }
  245.  
  246. /* set variable item names */
  247. void inititem()
  248. {
  249.   int i;
  250.   scrollname(TRUE,0);
  251.   for(i=0;i<NUMSCROLLS;i++) {
  252.     Objects[SCROLLID+i].objstr = salloc(scrollname(FALSE,i));
  253.   }
  254.   potionname(TRUE,0);
  255.   for(i=0;i<NUMPOTIONS;i++) {
  256.     Objects[POTIONID+i].objstr = salloc(potionname(FALSE,i));
  257.   }
  258.   stickname(TRUE,0);
  259.   for(i=0;i<NUMSTICKS;i++) {
  260.     Objects[STICKID+i].objstr = salloc(stickname(FALSE,i));
  261.   }
  262.   bootname(TRUE,0);
  263.   for(i=0;i<NUMBOOTS;i++) {
  264.     Objects[BOOTID+i].objstr = salloc(bootname(FALSE,i));
  265.   }
  266.   cloakname(TRUE,0);
  267.   for(i=0;i<NUMCLOAKS;i++) {
  268.     Objects[CLOAKID+i].objstr = salloc(cloakname(FALSE,i));
  269.   }
  270.   ringname(TRUE,0);
  271.   for(i=0;i<NUMRINGS;i++) {
  272.     Objects[RINGID+i].objstr = salloc(ringname(FALSE,i));
  273.   }
  274. }
  275.  
  276.